package com.ihd.ihardware.view.tzc.discovery.view;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.ihd.ihardware.R;
import com.ihd.ihardware.common.AppConstans;
import com.ihd.ihardware.databinding.ActivityMsgBinding;
import com.ihd.ihardware.pojo.MsgRes;
import com.ihd.ihardware.view.tzc.discovery.viewmodel.MsgViewModel;

import cn.wowjoy.commonlibrary.base.BaseActivity;
import cn.wowjoy.commonlibrary.base.BaseConsumer;

public class MsgActivity extends BaseActivity<ActivityMsgBinding, MsgViewModel> {

    @Override
    protected void init(Bundle savedInstanceState) {
        mImmersionBar.statusBarDarkFont(true).init();
        binding.mtitlebar.setTitle("消息中心");
        binding.mtitlebar.setLeftBack(this);

        binding.plRL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MsgActivity.this, MsgsActivity.class);
                i.putExtra("msgType", "1");
                startActivity(i);
            }
        });

        binding.dzRL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MsgActivity.this, MsgsActivity.class);
                i.putExtra("msgType", "2");
                startActivity(i);
            }
        });

        binding.fsRL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MsgActivity.this, MsgsActivity.class);
                i.putExtra("msgType", "3");
                startActivity(i);
            }
        });

        binding.tzRL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MsgActivity.this, MsgsActivity.class);
                i.putExtra("msgType", "0");
                startActivity(i);
            }
        });

        setRx(AppConstans.UNREADMSG, new BaseConsumer<MsgRes>() {
            @Override
            protected void onStart() {
            }

            @Override
            protected void onSuccess(MsgRes mLiveData) {
                if (!TextUtils.isEmpty(mLiveData.getData().getCommentMsg()))
                    binding.plTV.setText(mLiveData.getData().getCommentMsg());
                if (!TextUtils.isEmpty(mLiveData.getData().getUnReadCommentMsgCount()) && !"0".equals(mLiveData.getData().getUnReadCommentMsgCount()))
                    binding.plBTV.showTextBadge(mLiveData.getData().getUnReadCommentMsgCount());
                else
                    binding.plBTV.setVisibility(View.GONE);
                if (!TextUtils.isEmpty(mLiveData.getData().getUnReadTagMsgCount()) && !"0".equals(mLiveData.getData().getUnReadTagMsgCount()))
                    binding.dzBTV.showTextBadge(mLiveData.getData().getUnReadTagMsgCount());
                else
                    binding.dzBTV.setVisibility(View.GONE);
                if (!TextUtils.isEmpty(mLiveData.getData().getUnReadConcernMsgCount()) && !"0".equals(mLiveData.getData().getUnReadConcernMsgCount()))
                    binding.fsBTV.showTextBadge(mLiveData.getData().getUnReadConcernMsgCount());
                else
                    binding.fsBTV.setVisibility(View.GONE);
                if (!TextUtils.isEmpty(mLiveData.getData().getUnReadSystemMsgCount()) && !"0".equals(mLiveData.getData().getUnReadSystemMsgCount()))
                    binding.tzBTV.showTextBadge(mLiveData.getData().getUnReadSystemMsgCount());
                else
                    binding.tzBTV.setVisibility(View.GONE);
            }

            @Override
            protected void onError(Throwable error) {
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        viewModel.unReadMsgs();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_msg;
    }

    @Override
    protected Class getViewModelClass() {
        return MsgViewModel.class;
    }

}
